package org.jeecg.modules.papers.webController;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.common.system.query.QueryRuleEnum;
import org.jeecg.config.shiro.IgnoreAuth;
import org.jeecg.modules.papers.entity.JkPapers;
import org.jeecg.modules.papers.service.IJkPapersService;
import org.jeecg.modules.util.DictUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

@Tag(name="前端jk_papers论文t企业接口")
@RestController
@RequestMapping("/api/papers")
@Slf4j
public class JKPapersWebController {

    @Autowired
    private IJkPapersService jkPapersService;
    @Autowired
    DictUtils dictUtils;

    /**
     * 分页列表查询
     *
     * @param jkPapers
     * @param pageNo
     * @param pageSize
     * @param req
     * @return
     */
    //@AutoLog(value = "论文-分页列表查询")
    @Operation(summary="论文-分页列表查询")
    @GetMapping(value = "/list")
    @IgnoreAuth
    public Result<IPage<JkPapers>> queryPageList(JkPapers jkPapers,
                                                 @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
                                                 @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
                                                 HttpServletRequest req) {
        QueryWrapper<JkPapers> queryWrapper = QueryGenerator.initQueryWrapper(jkPapers, req.getParameterMap());
        queryWrapper.orderByAsc("sn");
        Page<JkPapers> page = new Page<JkPapers>(pageNo, pageSize);
        IPage<JkPapers> pageList = jkPapersService.page(page, queryWrapper);
        return Result.OK(pageList);
    }

    /**
     * 通过id查询
     *
     * @param id
     * @return
     */
    //@AutoLog(value = "论文-通过id查询")
    @Operation(summary="论文-通过id查询")
    @GetMapping(value = "/queryById")
    @IgnoreAuth
    public Result<JkPapers> queryById(@RequestParam(name="id",required=true) String id) {
        JkPapers jkPapers = jkPapersService.getById(id);
        if(jkPapers==null) {
            return Result.error("未找到对应数据");
        }

        String papersType = dictUtils.getDictItemName("papers_type",jkPapers.getPaperFieldType());
        jkPapers.setPaperFieldType(papersType);
        return Result.OK(jkPapers);
    }



}
